package com.imooc.reader.management.controller;

import com.imooc.reader.management.dto.ResponseDTO;
import com.imooc.reader.management.entity.Menu;
import com.imooc.reader.management.service.MenuService;
import jakarta.annotation.Resource;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/menus")
public class MenuController {
    @Resource
    private MenuService menuService;

    @GetMapping("")
    public ResponseDTO getMenuByUsername() {
        // 获取保存在session中的用户名数据
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String username = authentication.getName();
        List<Menu> list = menuService.selectByUsername(username);
        return new ResponseDTO().put("menuList", list);
    }

}
